/*
 * Copyright (C) 2003, 2004 Rex Ford
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
package GamePlay.GameObjects;
import GamePlay.GameEnv;
import GamePlay.Location;
import java.awt.*;
import java.awt.image.*;

public class Star extends GameObject 
{
	private int size;
	
	public Star(GameEnv env) 
	{
		super(env);
		int rand = (int) (Math.random() * 900);
		myLoc = new Location(rand, -5);
		size = (int) (Math.random() * 8) + 1;
		BufferedImage bi = new BufferedImage(size, size,
				BufferedImage.TYPE_INT_ARGB);
		Graphics2D g = bi.createGraphics();
		//outer star
		g.setColor(getColor(size));
		g.fillOval(1, 1, size, size);
		//inner
		Color c1=mix(getColor(size*2),new Color(255,255,255));
		g.setColor(c1);
		g.fillOval((int)(Math.random()*size),(int)(Math.random()*size),size,size);
		Color c2=mix(c1,new Color(160,180,255));
		g.setColor(mix(c2,new Color(160,180,255)));
		g.fillOval((int)(Math.random()*size),(int)(Math.random()*size),size,size);
		myImage = bi;
	}
	
	//s is a number up to 18
	private Color getColor(int s) 
	{
		int e = (s / 18) * 255;
		Color c1 = new Color(e, e, e);
		Color c2 = getRandColor();
		Color c3 = mix(c1, c2);
		return c3;
	}
	
	private Color getRandColor() 
	{
		int r = (int) (Math.random() * 170+80);
		int g = (int) (Math.random() * 170+80);
		int b = (int) (Math.random() * 95+160);
		return new Color(r, g, b);
	}
	
	private Color mix(Color c1, Color c2) 
	{
		int r1 = c1.getRed();
		int g1 = c1.getGreen();
		int b1 = c1.getBlue();
		int r2 = c2.getRed();
		int g2 = c2.getGreen();
		int b2 = c2.getBlue();
		return new Color((r1 + r2) / 2, (g1 + g2) / 2, (b1 + b2) / 2);
	}
	
	public void pulse(long millis) 
	{		
		myLoc.moveY((size/150.0)*millis);
		if (myLoc.getY() > 710)
			removeMe();
	}

	
	public void collide(GameObject blah){}
}